#include <iostream>
#include <thread>
#include <sys/eventfd.h>
#include <unistd.h>

void routine1(int evfd)
{
    uint64_t value = 0;
    while(true) {
        if(read(evfd, &value, sizeof(value)) == sizeof(value)) {
            std::cout << "收到通知" << std::endl;
            break;
        }
        else {
            std::cout << "没有收到通知" << std::endl;
        }
    }
    std::cout << "线程退出" << std::endl;
}

int main()
{
    int evfd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
    if(evfd < 0) {
        std::cout << "create eventfd error" << std::endl;
    }
    std::thread t1(routine1, evfd);
    uint64_t value = 1;
    sleep(3);
    write(evfd, &value, sizeof(value));

    t1.join();
    close(evfd);
    return 0;
}